package myJs.api

import japgolly.scalajs.react.extra.Ajax
import myJs.myPkg.MyFetch
import org.scalajs.dom.{File, FormData, XMLHttpRequest, window}
import upickle.default.{read, write}
import shared.pojo.Pojo._
import org.scalajs.macrotaskexecutor.MacrotaskExecutor.Implicits._

/** Created by yz on 18/5/2022
  */
object Api {

  val apiUrl = s"${window.location.protocol}//${window.location.host}/metaboCloundPlatform"

  val images=s"${window.location.protocol}//${window.location.host}/assets/images"

  val workflowMission = WorkflowMission
  val data = Data
  val matrixFileData = MatrixFileDataApi
  val groupFileData = GroupFileData
  val varInfoFileData = VarInfoFileData
  val soft = Soft
  val missionTool = MissionTool
  val mission = Mission

  def login(request: LoginUserData) = {
    val url = s"${Api.apiUrl}/loginApi"
    Ajax
      .post(s"${url}")
      .setRequestContentTypeJson
      .send(write(request))
      .asAsyncCallback
      .map { xhr =>
        read[ValidData](xhr.responseText)
      }
  }

}
